home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / WINPROGS.ARJ / POPPAD1.C < prev    next >
Text File  |  1990-12-26  |  4KB  |  122 lines

  1. /*   poppad1.c   -   Popup Editor Using Child Window Edit Box
  2.                      Petzold
  3. */
  4.  
  5. #include <windows.h>
  6.  
  7.  
  8. long FAR PASCAL WndProc  (HWND, WORD, WORD, LONG);
  9.  
  10. int PASCAL WinMain (HANDLE hInstance,
  11.                     HANDLE hPrevInstance,
  12.                     LPSTR  lpszCmdParam,
  13.                     int    nCmdShow)
  14.                     
  15.   {
  16.   static char szAppName[] = "poppad1";
  17.   HWND        hwnd;
  18.   MSG         msg;
  19.   WNDCLASS    wndclass;
  20.   
  21.  
  22.   if (!hPrevInstance)
  23.     {      
  24.      wndclass.style            = CS_HREDRAW | CS_VREDRAW;
  25.      wndclass.lpfnWndProc      = WndProc;
  26.      wndclass.cbClsExtra       = 0;
  27.      wndclass.cbWndExtra       = 0;
  28.      wndclass.hInstance        = hInstance;
  29.      wndclass.hIcon            = NULL;
  30.      wndclass.hCursor          = LoadCursor (NULL, IDC_ARROW);
  31.      wndclass.hbrBackground    = GetStockObject (WHITE_BRUSH);
  32.      wndclass.lpszMenuName     = NULL;
  33.      wndclass.lpszClassName    = szAppName;
  34.      
  35.      RegisterClass(&wndclass);
  36.      
  37.     }
  38.  
  39.   hwnd = CreateWindow (szAppName,
  40.                        szAppName,
  41.                        WS_OVERLAPPEDWINDOW,
  42.                        CW_USEDEFAULT,
  43.                        CW_USEDEFAULT,
  44.                        GetSystemMetrics (SM_CXSCREEN) /2,
  45.                        GetSystemMetrics (SM_CYSCREEN) /2,
  46.                        NULL,
  47.                        NULL,
  48.                        hInstance,
  49.                        NULL);
  50.                        
  51.                                                                                       
  52.   ShowWindow (hwnd, nCmdShow);
  53.   UpdateWindow (hwnd);
  54.   
  55.   while (GetMessage (&msg, NULL, 0, 0))
  56.     {
  57.     TranslateMessage (&msg);
  58.     DispatchMessage  (&msg);
  59.     }
  60.     
  61.   return msg.wParam;
  62.   }
  63.   
  64. long FAR PASCAL WndProc (HWND hwnd,
  65.                          WORD message,
  66.                          WORD wParam,
  67.                          LONG lParam)
  68.                          
  69.   {
  70.   static HWND hwndEdit;
  71.   
  72.   switch (message)
  73.     {
  74.     case WM_CREATE:
  75.       hwndEdit = CreateWindow ("edit",
  76.                                 NULL,
  77.                                 WS_CHILD | WS_VISIBLE | WS_VSCROLL |
  78.                                 WS_BORDER | ES_LEFT | ES_MULTILINE | 
  79.                                 ES_AUTOVSCROLL,
  80.                                 0,
  81.                                 0,
  82.                                 0,
  83.                                 0,
  84.                                 hwnd,
  85.                                 1,
  86.                                 ((LPCREATESTRUCT) lParam) -> hInstance, 
  87.                                 NULL);
  88.                                 
  89.       return 0;
  90.                                               
  91.      case WM_SIZE:
  92.        MoveWindow (hwndEdit,
  93.                    0, 
  94.                    0,
  95.                    LOWORD (lParam),
  96.                    HIWORD (lParam),
  97.                    TRUE);
  98.                    
  99.        return 0;
  100.        
  101.      case WM_SETFOCUS:
  102.        SetFocus (hwndEdit);
  103.        return 0;
  104.        
  105.      case WM_COMMAND:
  106.        if (wParam == 1 && HIWORD (lParam) == EN_ERRSPACE)
  107.          MessageBox (hwnd, "Edit Control out of Space",
  108.                      "PopPad Version 1",
  109.                      MB_OK | MB_ICONSTOP);
  110.          
  111.        return 0;
  112.        
  113.  
  114.     case WM_DESTROY:
  115.       PostQuitMessage (0);
  116.       return 0;
  117.     }
  118.     
  119.   return DefWindowProc (hwnd, message, wParam, lParam);
  120.   }
  121.                   
  122.